package com.example.cola.client.api.dto;

import lombok.Data;

import java.util.List;

/**
 * 分页结果对象
 * 
 * @author 资深开发专家
 * @version 1.0
 */
@Data
public class PageResult<T> {
    
    private List<T> records;
    private long total;
    private int page;
    private int size;
    private int pages;
    
    public static <T> PageResult<T> of(List<T> records, long total, int page, int size) {
        PageResult<T> result = new PageResult<>();
        result.records = records;
        result.total = total;
        result.page = page;
        result.size = size;
        result.pages = (int) Math.ceil((double) total / size);
        return result;
    }
}
